<?php

namespace App\Module\Api\Controllers;
use App\Exceptions\Customize\ParamsException;
use App\Module\Api\Controllers\Request\AddCardRequest;
use App\Module\Api\Validator\AddCardValidator;
use App\System\Base\Services\TokenService;
use App\System\Cis\Repositories\CisBankAccountRepository;
use App\System\Cis\Repositories\CisUserRepository;

/**
 *添加编辑银行卡
 */
class AddCardController extends Controller
{

    public function __construct()
    {
        $this->query = new AddCardRequest();
        parent::__construct();


    }

    public function index()
    {

//        echo 'here';die;
        (new AddCardValidator())->check();
        $master_id = TokenService::getMasterId();
        $user = CisUserRepository::getInstance();
        $master_info = $user->checkPayPassword($master_id,$this->query->payPassword);
        if(!$master_info)
        {
            throw new ParamsException([
                'error_code' => '1000',
                'message'    => '支付密码错误',
            ]);
        }
        $band = CisBankAccountRepository::getInstance();
        $res = $band->updateData($this->query,$master_id);
        return apiResponse($res);
    }
}
